﻿<div style="width:1000px;height:70%;margin:5px auto;">
    <div class="easyui-panel" style="height:428px;" title="">
    <table align="center" bgcolor="#D6D6D6" border="0" cellpadding="0" cellspacing="0" width="98%">
        <tr>
            <td align="center" bgcolor="#FFFFFF" valign="top">
                <form action="" method="post" id="registrationForm" name="registrationForm">
                    <input type="hidden" id="studentId" name="studentId"/>
                    <table border="0" cellpadding="4" cellspacing="1" class="student" width="80%">
                        <tr bgcolor="#F9FAF3">
                            <td align="right" width="15%">
                                通知书编号：
                            </td>
                            <td width="30%">
                                <input class="easyui-textbox" maxlength="18" id="noticeNumber" name="noticeNumber"
                                       style="width:180px;" type="text" data-options="prompt:'输入通知书号回车查询'"/>
                                <font color="red">*</font>
                                <a class="easyui-linkbutton" data-options="iconCls:'icon-search'" href="#"
                                   onclick="queryStudentByNoticeNumber()" id="QueryBtn">查询</a>
                            </td>
                            <td align="right" width="15%">
                                考生号：
                            </td>
                            <td width="25%">
                                <input class="easyui-textbox" name="examineeNumber" readonly="readonly" id="examineeNumber" type="text"/>
                                <font color="red">*</font>
                            </td>
                        </tr>
                        <tr>
                            <td align="right">
                                姓名：
                            </td>
                            <td>
                                <input class="easyui-textbox" name="studentName" readonly="readonly" id="studentName" type="text"/>
                                <font color="red">*</font>
                            </td>
                            <td align="right" rowspan="5">
                                照片：<font color="red">*</font>
                            </td>
                            <td rowspan="5">
                                <img id="upload_face" src="__PUBLIC__/images/noface.gif"
                                     style="width:108px;height:128px;"/>
                                <input id="face" name="face" type="file"/>
                                <input id="studentFace" name="studentFace" type="hidden"/>
                            </td>
                        </tr>
                        <tr bgcolor="#F9FAF3">
                            <td align="right">
                                性别：
                            </td>
                            <td>
                                <select class="easyui-combobox" editable="false" id="sex" name="sex" panelheight="auto"
                                        style="width:160px;" readonly="readonly">
                                    <option value="-1">请选择</option>
                                    <option value="0">男</option>
                                    <option value="1">女</option>
                                </select>
                                <font color="red">*</font>
                            </td>
                        </tr>
                        <tr>
                            <td align="right">
                                身份证号：
                            </td>
                            <td>
                                <input class="easyui-textbox" data-options="events:{blur:exitIdCard}" id="idcard"
                                       name="idcard" readonly="readonly" style="width:160px;" type="text"/>
                                <font color="red">*</font>
                            </td>
                        </tr>
                        <tr bgcolor="#F9FAF3">
                            <td align="right">
                                出生日期：
                            </td>
                            <td width="25%">
                                <input class="easyui-textbox" readonly="readonly" id="birthday" name="birthday" style="width:160px;"
                                       type="text"/>
                                <font color="red">*</font>
                            </td>
                        </tr>
                        <tr>
                            <td align="right">
                                民族：
                            </td>
                            <td>
                                <select class="easyui-combobox" editable="false" id="nation" name="nation"
                                        style="width:160px;" readonly="readonly">
                                    <option value="-1">请选择</option>
                                </select>
                                <font color="red">*</font>
                            </td>
                        </tr>
                        <tr bgcolor="#F9FAF3">
                            <td align="right">
                                院系：
                            </td>
                            <td width="25%">
                                <select class="easyui-combobox" editable="false" id="department" name="department"
                                        panelheight="auto" style="width:160px;" readonly="readonly">
                                    <option value="-1">请选择</option>
                                </select>
                                <font color="red">*</font>
                            </td>
                            <td align="right">
                                专业：
                            </td>
                            <td>
                                <select class="easyui-combobox" editable="false" id="major" name="major"
                                        style="width:160px;" readonly="readonly">
                                    <option value="-1">请选择</option>
                                </select>
                                <font color="red">*</font>
                            </td>
                        </tr>
                        <tr>
                            <td align="right">
                                邮政编码：
                            </td>
                            <td width="25%">
                                <input class="easyui-textbox" readonly="readonly" name="postcode" id="postcode" type="text"/>
                                <font color="red">*</font>
                            </td>
                            <td align="right">
                                毕业中学：
                            </td>
                            <td>
                                <input class="easyui-textbox" readonly="readonly" name="finishSchool" id="finishSchool" type="text"/>
                                <font color="red">*</font>
                            </td>
                        </tr>
                        <tr bgcolor="#F9FAF3">
                            <td align="right">
                                本人联系电话：
                            </td>
                            <td width="25%">
                                <input class="easyui-textbox" readonly="readonly" name="telphone" id="telphone" type="text"/>
                                <font color="red">*</font>
                            </td>
                            <td align="right">
                                家长联系电话：
                            </td>
                            <td>
                                <input class="easyui-textbox" readonly="readonly" name="parentTel" id="parentTel" type="text"/>
                                <font color="red">*</font>
                            </td>
                        </tr>
                        <tr>
                            <td align="right">
                                家庭住址：
                            </td>
                            <td colspan="3">
                                <input class="easyui-textbox" readonly="readonly" name="homeAddress" id="homeAddress" style="width:600px;"
                                       type="text"/>
                                <font color="red">*</font>
                            </td>
                        </tr>
                        <tr>
                            <td align="center" colspan="4">
                                <a class="easyui-linkbutton" data-options="iconCls:'icon-save'" href="#"
                                   onclick="validateForm()" id="saveBtn">
                                    保存
                                </a>
                                <a class="easyui-linkbutton" data-options="iconCls:'icon-reload'" href="#"
                                   onclick="resetForm()" id="resetBtn">
                                    重置
                                </a>
                            </td>
                        </tr>
                    </table>
                </form>
            </td>
        </tr>
    </table>
</div>
</div>
<script>
    $(function () {
        $('#face').uploadify({
            swf: PUBLIC + '/Uploadify/uploadify.swf', //引入Uploadify核心Flash文件
            uploader: Url, //PHP处理脚本地址
            width: 120, //上传按钮宽度
            height: 30, //上传按钮高度
            fileSizeLimit: 2048, //上传图片大小不超过2M
            buttonImage: PUBLIC + '/Uploadify/browse-btn.png', //上传按钮背景图地址
            fileTypeDesc: 'Image File', //选择文件提示文字
            fileTypeExts: '*.jpeg; *.jpg; *.png; *.gif', //允许选择的文件类型
            formData: {
                'session_id': sid
            },
            //上传成功后的回调函数
            onUploadSuccess: function (file, data, response) {
                eval('var data = ' + data);
                if (data.status) {
                    $('input[name=studentFace]').val(data.path);
                    $('#upload_face').attr('src', ROOT + '/' + data.path);
                } else {
                    alert(data.msg);
                }
            }
        });
        //加载民族xml数据
        $.ajax({
            url: nationUrl,
            datatype: 'xml',
            type: 'get',
            success: function (xml) {
                $.each($(xml).find('Nation'), function (k, v) {
                    $('#nation').append('<option value=' + $(v).attr('ID') + '>' + $(v).attr('NationName') + '</option>')
                });
                $("#nation").combobox({});
            },
            async: false
        });
        //加载院系xml数据
        $.ajax({
            url: departmentUrl,
            datatype: 'json',
            type: 'post',
            success: function (result) {
                for (i=0;i<result.length;i++) {
                    $('#department').append('<option value=' + result[i].id + '>' + result[i].department + '</option>');
                }
                $("#department").combobox({
                    onChange: function (new_value, old_value) {
                        department_OnChange(new_value);
                    }
                });
                $("#department").combobox({});
            },
            async: false
        });
        $('#noticeNumber').textbox({
                inputEvents: $.extend({}, $.fn.textbox.defaults.inputEvents, {
                    keypress: function (e) {
                        if (e.keyCode == 13) {
                            queryStudentByNoticeNumber();
                         }
                     }
                })
        });
    });

    function department_OnChange(deptId) {
        $('#major').empty();
        $('#major').append('<option value=-1>请选择</option>');
        if (deptId != -1) {
            getMajorData('#major', deptId);
        } else {
            $('#major').combobox({});
        }
    }

    function resetForm() {
        $('input[textboxname=studentName]').textbox('setValue', '');
        $('input[textboxname=noticeNumber]').textbox('setValue', '');
        $('input[textboxname=examineeNumber]').textbox('setValue', '');
        $('input[textboxname=idcard]').textbox('setValue', '');
        $('input[textboxname=birthday]').textbox('setValue', '');
        $('input[textboxname=postcode]').textbox('setValue', '');
        $('input[textboxname=finishSchool]').textbox('setValue', '');
        $('input[textboxname=telphone]').textbox('setValue', '');
        $('input[textboxname=parentTel]').textbox('setValue', '');
        $('input[textboxname=homeAddress]').textbox('setValue', '');
        $("#sex").combobox('setValue',-1);
        $("#sex").combobox('setText', '请选择');
        $("#nation").combobox('setValue',-1);
        $("#nation").combobox('setText', '请选择');
        $("#department").combobox('setValue',-1);
        $("#department").combobox('setText', '请选择');
        $("#major").combobox('setValue',-1);
        $("#major").combobox('setText', '请选择');
        $('#studentFace').val('');
        $('#face').val('');
        $('#studentId').val('');
        $('#upload_face').attr('src', PUBLIC + '/images/noface.gif');
        $('input[textboxname=examineeNumber]').textbox({readonly:true});
        $('input[textboxname=studentName]').textbox({readonly:true});
        $('input[textboxname=idcard]').textbox({readonly:true});
        $('input[textboxname=birthday]').textbox({readonly:true});
        $('input[textboxname=postcode]').textbox({readonly:true});
        $('input[textboxname=finishSchool]').textbox({readonly:true});
        $('input[textboxname=telphone]').textbox({readonly:true});
        $('input[textboxname=parentTel]').textbox({readonly:true});
        $('input[textboxname=homeAddress]').textbox({readonly:true});
        $('input[textboxname=noticeNumber]').textbox({readonly:false});
        $("#sex").combobox({readonly: true});
        $("#nation").combobox({readonly: true});
        $("#department").combobox({readonly: true});
        $("#major").combobox({readonly: true});
        $('input[textboxname=noticeNumber]').textbox().next('span').find('input').focus();
    }

    function queryStudentByNoticeNumber() {
        if ($.trim($('input[textboxname=noticeNumber]').textbox('getValue')) == "") {
            return;
        }
        noticeNumber = $.trim($('input[textboxname=noticeNumber]').textbox('getValue'));
        $.ajax({
            url: queryStudentUrl,
            datatype: 'json',
            type: 'post',
            data: 'noticeNumber=' + noticeNumber,
            success: function (result) {
                if (result.length == 0) {
                    $.messager.show({
                        title: '系统提示',
                        msg: "没有找到该新生"
                    });
                    resetForm();
                } else {
                    $('input[textboxname=examineeNumber]').textbox({readonly: false});
                    $('input[textboxname=studentName]').textbox({readonly: false});
                    $('input[textboxname=idcard]').textbox({readonly: false});
                    $('input[textboxname=birthday]').textbox({readonly: false});
                    $('input[textboxname=postcode]').textbox({readonly: false});
                    $('input[textboxname=finishSchool]').textbox({readonly: false});
                    $('input[textboxname=telphone]').textbox({readonly: false});
                    $('input[textboxname=parentTel]').textbox({readonly: false});
                    $('input[textboxname=homeAddress]').textbox({readonly: false});
                    $('input[textboxname=noticeNumber]').textbox({readonly: true});
                    $("#sex").combobox({readonly: false});
                    $("#nation").combobox({readonly: false});
                    $("#department").combobox({readonly: false});
                    $("#major").combobox({readonly: false});
                    $('input[textboxname=studentName]').textbox('setValue', result[0].studentname);
                    $('input[textboxname=examineeNumber]').textbox('setValue', result[0].examineenumber);
                    $('input[textboxname=idcard]').textbox('setValue', result[0].idcard);
                    checkIDCard($('input[name=idcard]').val());
                    $("#sex").combobox('setText', result[0].sexvalue);
                    setValueByText('#sex', result[0].sexvalue);
                    $("#department").combobox('setText', result[0].departmentvalue);
                    setValueByText('#department', result[0].departmentvalue);
                    $("#nation").combobox('setText', result[0].nationvalue);
                    setValueByText('#nation', result[0].nationvalue);
                    $("#major").combobox('setText', result[0].majorvalue);
                    setValueByText('#major', result[0].majorvalue);
                    $('input[textboxname=postcode]').textbox('setValue', result[0].postcode);
                    $('input[textboxname=finishSchool]').textbox('setValue', result[0].finishschool);
                    $('input[textboxname=telphone]').textbox('setValue', result[0].telphone);
                    $('input[textboxname=parentTel]').textbox('setValue', result[0].parenttel);
                    $('input[textboxname=homeAddress]').textbox('setValue', result[0].homeaddress);
                    $('#studentId').val(result[0].id);
                    $('input[textboxname=examineeNumber]').textbox().next('span').find('input').focus();
                }
            },
            async: false
        });
    }

    function setValueByText(selector, text) {
        data = $(selector).combobox('getData');
        i = 0;
        for (i = 0; i < data.length; i++) {
            if (data[i].text == text) {
                break;
            }
        }
        if (i < data.length) {
            $(selector).combobox('setValue', data[i].value);
        } else {
            $(selector).combobox('setValue', -1);
        }
    }

    function checkIDCard(idcard) {
        regIdCard = /^(^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$)|(^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])((\d{4})|\d{3}[Xx])$)$/;
        idCard = $.trim(idcard);
        if (idCard == "") {
            $('input[textboxname=birthday]').textbox('setValue', '');
        } else {
            if (regIdCard.test(idCard)) {
                year = idCard.substring(6, 10);
                month = idCard.substring(10, 12);
                day = idCard.substring(12, 14);
                $('input[textboxname=birthday]').textbox('setValue', year + "-" + month + "-" + day);
            } else {
                $.messager.show({
                    title: '系统提示',
                    msg: '身份证号码有误'
                });
                $('input[textboxname=idcard]').textbox('setValue', '');
                $('input[textboxname=birthday]').textbox('setValue', '');
            }
        }
    }

    function exitIdCard() {
        checkIDCard($(this).val());
    }

    function validateForm() {
        if ($.trim($('input[textboxname=noticeNumber]').textbox('getValue')) == "") {
            $.messager.show({
                title: '系统提示',
                msg: "通知书编号没有填写"
            });
            $('input[textboxname=noticeNumber]').textbox().next('span').find('input').focus();
            return;
        }
        if ($.trim($('input[textboxname=examineeNumber]').textbox('getValue')) == "") {
            $.messager.show({
                title: '系统提示',
                msg: "考生号没有填写"
            });
            $('input[textboxname=examineeNumber]').textbox().next('span').find('input').focus();
            return;
        }
        if ($.trim($('input[textboxname=studentName]').textbox('getValue')) == "") {
            $.messager.show({
                title: '系统提示',
                msg: "新生名字没有填写"
            });
            $('input[textboxname=studentName]').textbox().next('span').find('input').focus();
            return;
        }
        if ($("#sex").combobox('getValue') == -1) {
            $.messager.show({
                title: '系统提示',
                msg: "请选择性别"
            });
            return;
        }
        if ($.trim($('input[textboxname=idcard]').textbox('getValue')) == "") {
            $.messager.show({
                title: '系统提示',
                msg: "身份证号没有填写"
            });
            $('input[textboxname=idcard]').textbox().next('span').find('input').focus();
            return;
        }
        if ($.trim($('input[textboxname=birthday]').textbox('getValue')) == "") {
            $.messager.show({
                title: '系统提示',
                msg: "出生日期没有填写"
            });
            $('input[textboxname=idcard]').textbox().next('span').find('input').focus();
            return;
        }
        if ($("#nation").combobox('getValue') == -1) {
            $.messager.show({
                title: '系统提示',
                msg: "请选择民族"
            });
            return;
        }
        if ($("#department").combobox('getValue') == -1) {
            $.messager.show({
                title: '系统提示',
                msg: "请选择院系"
            });
            return;
        }
        if ($("#major").combobox('getValue') == -1) {
            $.messager.show({
                title: '系统提示',
                msg: "请选择专业"
            });
            return;
        }
        if ($.trim($('input[textboxname=postcode]').textbox('getValue')) == "") {
            $.messager.show({
                title: '系统提示',
                msg: "邮政编码没有填写"
            });
            $('input[textboxname=postcode]').textbox().next('span').find('input').focus();
            return;
        }
        if ($.trim($('input[textboxname=finishSchool]').textbox('getValue')) == "") {
            $.messager.show({
                title: '系统提示',
                msg: "毕业中学没有填写"
            });
            $('input[textboxname=finishSchool]').textbox().next('span').find('input').focus();
            return;
        }
        if ($.trim($('input[textboxname=telphone]').textbox('getValue')) == "") {
            $.messager.show({
                title: '系统提示',
                msg: "本人电话没有填写"
            });
            $('input[textboxname=telphone]').textbox().next('span').find('input').focus();
            return;
        }
        if ($.trim($('input[textboxname=parentTel]').textbox('getValue')) == "") {
            $.messager.show({
                title: '系统提示',
                msg: "家长电话没有填写"
            });
            $('input[textboxname=parentTel]').textbox().next('span').find('input').focus();
            return;
        }
        if ($.trim($('input[textboxname=homeAddress]').textbox('getValue')) == "") {
            $.messager.show({
                title: '系统提示',
                msg: "家庭地址没有填写"
            });
            $('input[textboxname=homeAddress]').textbox().next('span').find('input').focus();
            return;
        }
        if ($('#studentFace').val() == "") {
            $.messager.show({
                title: '系统提示',
                msg: "请上传新生照片"
            });
            return;
        }
        if ($.trim($('#studentId').val()) == "") {
            $.messager.show({
                title: '系统提示',
                msg: "请上传新生照片"
            });
            return;
        }
        doregistration();
    }

    function doregistration() {
        $("#registrationForm").ajaxSubmit({
            url: registrationUrl,
            type: "post",
            dataType: "json",
            beforeSubmit: function (arr, $form, options) {
                //将select中的文本值手动加到请求参数中
                obj_department = {
                    "name": "departmentValue",
                    "value": $("#department").combobox('getText'),
                    "type": "hidden",
                    "required": false
                }
                arr.push(obj_department);
                obj_major = {
                    "name": "majorValue",
                    "value": $("#major").combobox('getText'),
                    "type": "hidden",
                    "required": false
                }
                arr.push(obj_major);
                obj_nation = {
                    "name": "nationValue",
                    "value": $("#nation").combobox('getText'),
                    "type": "hidden",
                    "required": false
                }
                arr.push(obj_nation);
                obj_sex = {
                    "name": "sexValue",
                    "value": $("#sex").combobox('getText'),
                    "type": "hidden",
                    "required": false
                }
                arr.push(obj_sex);
            },
            //提交成功后的回调函数
            success: function (result, status, xhr, $form) {
                $.messager.show({
                    title: '系统提示',
                    msg: result.msg,
                    timeout: 500,
                    showType: 'slide'
                });
                if (result.errorCode == 0) {
                    resetForm();
                }
            },
            error: function (xhr, status, error, $form) {
            },
            complete: function (xhr, status, $form) {
            }
        });
    }
</script>